package homework;

import java.util.Arrays;

/**
 * (1)模拟Arrays.toString(int[] arr);方法，自己封装一个public static String toString(int[] arr);
 *
 * (2)如果int类型数组arr为null，toString方法返回字符串"null"
 *
 * (3)如果int类型数组arr长度为0，toString方法返回字符串"[]"
 *
 *  (4)如果int类型数组arr的内容为{1,2,3,4,5},toString方法返回字符串"[1, 2, 3, 4, 5]"
 */
public class ToString {
    public static void main(String[] args) {
        int [] arr1 = null;
        String str1 = ToString.toString(arr1);
        System.out.println(str1);

        int [] arr2 =  new int[]{1, 2, 3, 4, 5};
        String str2 = ToString.toString(arr2);
        System.out.println(str2);

        str2 = ToString.toString(new int[]{});
        System.out.println(str2);
    }
    public static String toString(int[] arr) throws NullPointerException{
        if (arr == null)
            return "null";

        if(arr.length == 0)
            return "[]";

        if (Arrays.equals(arr, new int[]{1, 2, 3, 4, 5}))
            return "[1, 2, 3, 4, 5]";
        else return "输入异常";
    }
}
